import java.util.ArrayList;
import java.util.List;

public class Solution130 {
    public void solve(char[][] board) {
        int m=board.length,n=board[0].length;
        int[] b=new int[m*n+1];
        for (int i=0;i<m*n+1;i++){
            b[i]=i;
        }
        for (int i=0;i<m;i++){
            for (int j=0;j<n;j++){
                if (board[i][j]=='O'){
                    if (i==0 || i==m-1 || j==0 || j==n-1){
                        int x=find(b,i*n+j);
                        int y=find(b,m*n);
                        b[x]=y;
                    }
                    if (i!=0 && board[i-1][j]=='O'){
                        int x=find(b,i*n+j);
                        int y=find(b,(i-1)*n+j);
                        b[x]=y;
                    }
                    if (j!=0 && board[i][j-1]=='O'){
                        int x=find(b,i*n+j);
                        int y=find(b,i*n+j-1);
                        b[x]=y;
                    }
                }
            }
        }
        for (int i=0;i<m;i++){
            for (int j=0;j<n;j++){
                if (board[i][j]=='O' && find(b,i*n+j)!=find(b,m*n)){
                    board[i][j]='X';
                }
            }
        }
    }

    private int find(int[] b, int t) {
        List<Integer> l=new ArrayList<>();
        while (b[t]!=t){
            l.add(t);
            t=b[t];
        }
        for (Integer integer : l) {
            b[integer]=t;
        }
        return t;
    }

    public static void main(String[] args) {
        char[][] board=new char[][]{{'X','X','X','X'},{'X','O','O','X'},{'X','X','O','X'},{'X','O','X','X'}};
        new Solution130().solve(board);
        for (char[] chars : board) {
            System.out.println(chars);
        }
    }
}
